package com.garbagecan.cachestudy.job;

public class Test {
	public static void main(String[] args) throws Exception {
		//testWithoutCache();
		testWithCache();
	}

	private static void testWithoutCache() {
		for (int idx = 1; idx <= 100; idx++) {
			final String thread_name = "thread_" + idx;
			new Thread(new Runnable() {
				public void run() {
					long begin = System.currentTimeMillis();
					JobService jobService = new JobServiceImplWithoutCache();
					jobService.getJobs();
					long end = System.currentTimeMillis();
					System.out.println("Time for " + thread_name + " : " + (end - begin));
				}
			}).start();
		}
	}

	private static void testWithCache() throws Exception {
//		JobService jobService = new JobServiceImplWithCache();
//		System.out.println(jobService.getJobs().size());
//		Thread.sleep(1000);
//		System.out.println(jobService.getJobs().size());
//		Thread.sleep(3000);
//		System.out.println(jobService.getJobs().size());
//		Thread.sleep(1000);
//		System.out.println(jobService.getJobs().size());
//		Thread.sleep(5000);
//		jobService.getJobs();
//		Thread.sleep(5000);
		
		for (int idx = 1; idx <= 100; idx++) {
			final String thread_name = "thread_" + idx;
			new Thread(new Runnable() {
				public void run() {
					long begin = System.currentTimeMillis();
					JobService jobService = new JobServiceImplWithCache();
					jobService.getJobs();
					long end = System.currentTimeMillis();
					System.out.println("Time for " + thread_name + " : " + (end - begin));
				}
			}).start();
		}
		for (int idx = 1; idx < 10; idx++) {
			final String thread_name = "submit_job_thread_" + idx;
			final String jobId = "job_" + idx;
			final String jobName = "job_" + idx;
			new Thread(new Runnable() {
				public void run() {
					long begin = System.currentTimeMillis();
					JobService jobService = new JobServiceImplWithCache();
					jobService.submitJob(new Job(jobId, jobName));
					long end = System.currentTimeMillis();
					System.out.println("Time for " + thread_name + " : " + (end - begin));
				}
			}).start();
		}
	}
}
